package MeteoCal.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "warningcomment")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Warningcomment.findAll", query = "SELECT w FROM Warningcomment w"),
    @NamedQuery(name = "Warningcomment.findByIdUser", query = "SELECT w FROM Warningcomment w WHERE w.warningcommentPK.idUser = :idUser"),
    @NamedQuery(name = "Warningcomment.findByIdComment", query = "SELECT w FROM Warningcomment w WHERE w.warningcommentPK.idComment = :idComment"),
    @NamedQuery(name = "Warningcomment.findByText", query = "SELECT w FROM Warningcomment w WHERE w.text = :text"),
    @NamedQuery(name = "Warningcomment.findByDateTime", query = "SELECT w FROM Warningcomment w WHERE w.dateTime = :dateTime")})
public class Warningcomment implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected WarningcommentPK warningcommentPK;
    @Size(max = 200)
    @Column(name = "Text")
    private String text;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Date_Time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTime;
    @JoinColumn(name = "idComment", referencedColumnName = "idComment", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Comment comment;
    @JoinColumn(name = "idUser", referencedColumnName = "Email", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;

    public Warningcomment() {
    }

    public Warningcomment(WarningcommentPK warningcommentPK) {
        this.warningcommentPK = warningcommentPK;
    }

    public Warningcomment(WarningcommentPK warningcommentPK, Date dateTime) {
        this.warningcommentPK = warningcommentPK;
        this.dateTime = dateTime;
    }

    public Warningcomment(String idUser, int idComment) {
        this.warningcommentPK = new WarningcommentPK(idUser, idComment);
    }

    public WarningcommentPK getWarningcommentPK() {
        return warningcommentPK;
    }

    public void setWarningcommentPK(WarningcommentPK warningcommentPK) {
        this.warningcommentPK = warningcommentPK;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getDateTime() {
        return dateTime;
    }

    public void setDateTime(Date dateTime) {
        this.dateTime = dateTime;
    }

    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (warningcommentPK != null ? warningcommentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Warningcomment)) {
            return false;
        }
        Warningcomment other = (Warningcomment) object;
        if ((this.warningcommentPK == null && other.warningcommentPK != null) || (this.warningcommentPK != null && !this.warningcommentPK.equals(other.warningcommentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Warningcomment[ warningcommentPK=" + warningcommentPK + " ]";
    }
    
}
